<?php
namespace yakexi;
if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Our base HTTP request handler. Clients should subclass this class.
 * Subclasses should override get(), post(), head(), options(), etc to handle
 * different HTTP methods.
 */
class RequestHandler
{
	public $request;
	public $response;

	public function __construct()
	{
	}

	public function get()
	{
		$this->error(405);
	}

	public function post()
	{
		$this->error(405);
	}

	public function delete()
	{
		$this->error(405);
	}

	public function options()
	{
		$this->error(405);
	}

	public function put()
	{
		$this->error(405);
	}

	public function trace()
	{
		$this->error(405);
	}

	public function handle_exception($exception, $debug_mode)
	{
	}

	public function error($code)
	{
		$this->response->clear();
		$this->response->set_status($code);
	}

	public function redirect($url, $permanent=False)
	{
		/*
		if (strpos($url, '://') === FALSE)
		{
			// Make the URI into a URL
			$url = URL::site($url, TRUE);
		}
		*/

		// Set the response status
		if ($permanent)
			$this->response->set_status(301);
		else
			$this->response->set_status(302);

		// Set the location header
		$this->response->headers['Location'] = $url;

		$this->response->clear();
		// Send headers
		$this->response->send_headers();

		// Stop execution
		exit;
	}

	public function initialize($request, $response)
	{
		$this->request = $request;
		$this->response = $response;
	}
}
